import { defineStore } from 'pinia'
import { ref } from 'vue'
// import { userGetInfoService } from '../../api/user'

// 用户模块 token setToken removeToken
export const useUserStore = defineStore(
  'big-user',
  () => {
    const token = ref()
    const setToken = (newToken) => {
      token.value = newToken
    }
    const removeToken = () => {
      token.value = ''
    }

    const user = ref({})
    const getUser = (res) => {
      // const res = await userGetInfoService() // 请求获取数据
      user.value = res
      console.log(user.value)
    }
    const setUser = (obj) => {
      user.value = obj
    }

    const nodeName = ref({})
    const setNodeName = (name) => {
      nodeName.value = name
      localStorage.setItem('nodeName', JSON.stringify(nodeName.value))
    }
    const getNodeName = () => {
      console.log(JSON.parse(localStorage.getItem('nodeName')))

      return JSON.parse(localStorage.getItem('nodeName'))
    }

    return {
      token,
      setToken,
      removeToken,
      user,
      getUser,
      setUser,
      setNodeName,
      getNodeName
    }
  },
  {
    persist: true
  }
)
